package Algos;

import java.util.Random;

import weka.classifiers.Classifier;
import weka.classifiers.Evaluation;
import weka.classifiers.bayes.NaiveBayes;
import weka.core.Instance;
import weka.core.Instances;

public class BayesienNaif {
	
	private Classifier tree = new NaiveBayes();
	private Evaluation eval;
	private int folds;
	
	public BayesienNaif() {
		this(10);
	}

	public BayesienNaif(int folds) {
		this.folds = folds;
	}

	public Evaluation getEval(){
		return eval;
	}
	
	public void train(Instances trainInstances){
		try {
			tree.buildClassifier(trainInstances);
			eval = new Evaluation(trainInstances);
			eval.crossValidateModel(tree, trainInstances, folds, new Random(1));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
		
	public double classer(Instance unlabelled) {
		try{
			return this.tree.classifyInstance(unlabelled);
		} catch (Exception e){
			e.printStackTrace();
		}
		return -1.0;
	}
	
	public int getFolds(){
		return folds;
	}
	
	public void setFolds(int folds){
		this.folds = folds;
	}
	
}
	
	
	

